# in root directory run:
# prove -v t/t1-junc-pos.t
use strict;
use warnings;
use Data::Dumper;
use lib '/Users/manuelcorpas/Documents/workspace/Junction_filter' ;
use Modules::Utilities;
use Modules::JunctionRW;
use Modules::JunctionFilter;

use Test::More tests => 11;

BEGIN { 
  use_ok('Modules::Utilities'); 
  use_ok('Modules::JunctionRW');
  use_ok('Modules::JunctionFilter');
}
my $root      = '/Users/manuelcorpas/Documents/workspace/Junction_filter' ;
my $conf_file = "conf/test_conf2.txt";
my $util      = Modules::Utilities->new;

ok( defined $util, 'Utilities returned something' );
 
$util->read_conf_file("$root/$conf_file");
my $filename  = $util->{DATA_PATH}.$util->{SAM_FILE};

ok( -e $filename, "SAM file exists" );

my $jrw       = Modules::JunctionRW->new($util);

ok( defined $jrw, 'Junction read write returned something' );

my $sam       = $jrw->parse_sam;

ok( defined $sam, 'SAM parser returned something' );
ok( -e "$filename.unspliced_reads", "Unspliced_reads file exists" );
ok( -e "$filename.spliced_reads_info", "Spliced_reads_info file exists" );
ok( -e "$filename.spliced_reads", "Spliced_reads file exists" );

my $filter    = Modules::JunctionFilter->new($util);
my $junctions = $filter->calc_junctions($sam);

my @juncs     = keys %$junctions;
map {print "$_\t".$junctions->{$_}{support    }    ."\t";
     print        $junctions->{$_}{left_flank }[0 ]."\t";
     print        $junctions->{$_}{right_flank}[-1]."\t";
     print        $junctions->{$_}{junc_start }    ."\t";
     print        $junctions->{$_}{junc_end   }    ."\n";
    }@juncs;
my $junc1         = '24199_25101_Mp1087439_TGAC_V1_scaffold_344';
my $support1      = $junctions->{$junc1}{support};
my $left_flank1   = $junctions->{$junc1}{left_flank }[0 ];
my $right_flank1  = $junctions->{$junc1}{right_flank}[-1];
my $query_strand1 = $junctions->{$junc1}{query_strand};

#print Dumper $junctions->{$junc1};

ok( exists $junctions->{$junc1}, "$junc1 exists" );
ok( $query_strand1       eq '-', "query strand"  );

is( $support1,       355, "support"           );
is( $left_flank1,  24102, "left flank start"  );
is( $right_flank1, 25197, "right flank end"   );


#ok( $support1 eq 355); 
   
=comment
my $filter    = Modules::JunctionFilter->new($util);

ok( defined $filter, 'Junction filter object returned something' );

my $junctions = $filter->calc_junctions($sam);

is( $junctions->{'24198_25100_Mp1087439_TGAC_V1_scaffold_344'}{support}, 335, ' Support 335');
#print Dumper $junctions;

=cut

